package com.ysd.lis.service.sta.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ysd.common.Result;
import com.ysd.lis.dto.sta.StaRoleDto;
import com.ysd.lis.dto.sta.StaRoleParam;
import com.ysd.lis.entity.sta.StaRoleMenu;
import com.ysd.lis.entity.sta.StaRoleModule;
import com.ysd.lis.mapper.sta.StaRoleMenuMapper;
import com.ysd.lis.service.sta.StaRoleMenuService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 * cold_chain.sys_Model 服务实现类
 * </p>
 *
 * @author prs
 * @since 2024-12-27
 */
@Service
public class StaRoleMenuServiceImpl extends ServiceImpl<StaRoleMenuMapper, StaRoleMenu> implements StaRoleMenuService {

    @Autowired
    StaRoleMenuMapper staRoleMenuMapper;

    @Override
    public Result batchAddRoleMenuList(StaRoleDto dto) {
        StaRoleModule staRoleModule = dto.getStaRoleModule();
        List<StaRoleMenu> staRoleMenuList = dto.getStaRoleMenuList();
        String staRoleId = staRoleModule.getStaRoleId();
        String staModId = staRoleModule.getStaModId();

        LambdaQueryWrapper<StaRoleMenu> roleModuleLambdaQueryWrapper = new LambdaQueryWrapper<StaRoleMenu>();
        roleModuleLambdaQueryWrapper
                .eq(StaRoleMenu::getStaRoleId, staRoleId)
                .eq(StaRoleMenu::getStaModId, staModId);
        // 删除模块信息
        int delete = staRoleMenuMapper.delete(roleModuleLambdaQueryWrapper);
        boolean b = this.saveBatch(staRoleMenuList);
        if(b){
            return Result.succ(1, "添加成功", null);
        }else {
            return Result.fail(400,"添加失败","");
        }
    }

    @Override
    public Result findRoleMenuList(StaRoleParam sysMenu) {
        String staRoleId = sysMenu.getStaRoleId();
        String staModId = sysMenu.getStaModId();
        LambdaQueryWrapper<StaRoleMenu> roleMenuQueryWrapper = new LambdaQueryWrapper<>();
        roleMenuQueryWrapper
                .eq(StaRoleMenu::getStaRoleId, staRoleId)
                .eq(StaRoleMenu::getStaModId, staModId);
        List<StaRoleMenu> roleMenuList = staRoleMenuMapper.selectList(roleMenuQueryWrapper);
        return Result.succ(1, "获取信息成功", roleMenuList);
    }
}
